import Vue from 'vue';
import VueRouter from 'vue-router';
import store from '@/store';
Vue.use(VueRouter);

const Layout = () => import('@/views/layout/Layout.vue');
const DockLayout = () =>
  import('@/views/apply-online/dock/components/DockLayout.vue');
const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    component: Layout,
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/Home.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
        meta: {},
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/Login.vue'),
    props: (route) => ({ ...route.query, ...route.params }),
  },
  {
    path: '/applyOnline',
    component: Layout,
    children: [
      {
        path: '/personalNeedApply',
        name: 'personalNeedApply',
        component: () =>
          import(
            '@/views/apply-online/personal/need-apply/PersonalNeedApply.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/personalApplyStep',
        name: 'personalApplyStep',
        component: () =>
          import(
            '@/views/apply-online/personal/need-apply/PersonalApplyStep.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/personalUnSubmit',
        name: 'personalUnSubmit',
        component: () =>
          import(
            '@/views/apply-online/personal/need-apply/PersonalUnSubmit.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/personalInProcess',
        name: 'personalInProcess',
        component: () =>
          import('@/views/apply-online/personal/handle/PersonalInProcess.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/personalCompleted',
        name: 'personalCompleted',
        component: () =>
          import('@/views/apply-online/personal/handle/PersonalCompleted.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      //单位的
      {
        path: '/companyNeedApply',
        name: 'companyNeedApply',
        component: () =>
          import(
            '@/views/apply-online/company/need-apply/CompanyNeedApply.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyApplyStep',
        name: 'companyApplyStep',
        component: () =>
          import(
            '@/views/apply-online/company/need-apply/CompanyApplyStep.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyUnSubmit',
        name: 'companyUnSubmit',
        component: () =>
          import('@/views/apply-online/company/need-apply/CompanyUnSubmit.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyInProcess',
        name: 'companyInProcess',
        component: () =>
          import('@/views/apply-online/company/handle/CompanyInProcess.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyCompleted',
        name: 'companyCompleted',
        component: () =>
          import('@/views/apply-online/company/handle/CompanyCompleted.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  {
    path: '/infoMaintain',
    component: Layout,
    children: [
      {
        path: '/userInfo',
        name: 'userInfo',
        component: () => import('@/views/info-maintain/user-info/UserInfo.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/userInfoQlf',
        name: 'userInfoQlf',
        component: () =>
          import('@/views/info-maintain/user-info/UserInfoQlf.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyInfo',
        name: 'companyInfo',
        component: () =>
          import('@/views/info-maintain/company-info/CompanyInfo.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/companyQlf',
        name: 'companyQlf',
        component: () =>
          import('@/views/info-maintain/company-info/CompanyQlf.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  {
    path: '/process',
    component: Layout,
    children: [
      {
        path: '/newDemo',
        name: "newDemo",
        component: () => import('@/views/process/newDemo.vue'),
        props: (route) => ({ ...route.query, ...route.params })
      },
      {
        path: '/processMain',
        name: 'processMain',
        component: () => import('@/views/process/components/ProcessMain.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/processAccepted',
        name: 'processAccepted',
        component: () => import('@/views/process/ProcessAccepted.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/processCorrection',
        name: 'processCorrection',
        component: () => import('@/views/process/ProcessCorrection.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/processReview',
        name: 'processReview',
        component: () => import('@/views/process/ProcessReview.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/processCompleted',
        name: 'processCompleted',
        component: () => import('@/views/process/ProcessCompleted.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  //电子证照查询
  {
    path: '/licenseQuery',
    component: Layout,
    children: [
      {
        path: '/licenseQuery',
        name: 'licenseQuery',
        component: () => import('@/views/license-query/LicenseQuery.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  //申请材料配置
  {
    path: '/materialConfig',
    component: Layout,
    children: [
      {
        path: '/materialConfig',
        name: 'materialConfig',
        component: () => import('@/views/material-config/MaterialConfig.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  //用户管理
  {
    path: '/userManagement',
    component: Layout,
    children: [
      {
        path: '/userManagement',
        name: 'userManagement',
        component: () => import('@/views/user-management/UserManagement.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
  //转出查询
  {
    path: '/licenseTransfer',
    name: 'licenseTransfer',
    component: () => import('@/views/license-query/LicenseMv.vue'),
    props: (route) => ({ ...route.query, ...route.params }),
  },
  //对接DockLayout
  {
    path: '/dock',
    component: DockLayout,
    props: (route) => ({ ...route.query, ...route.params }),
    children: [
      {
        path: '/dockPersonalApplyStep',
        name: 'dockPersonalApplyStep',
        component: () =>
          import(
            '@/views/apply-online/dock/personal/DockPersonalApplyStep.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalUserInfo',
        name: 'dockPersonalUserInfo',
        component: () =>
          import('@/views/apply-online/dock/personal/DockPersonalUserInfo.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalUserCert',
        name: 'dockPersonalUserCert',
        component: () =>
          import('@/views/apply-online/dock/personal/DockPersonalUserCert.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalUserInfoQlf',
        name: 'dockPersonalUserInfoQlf',
        component: () =>
          import(
            '@/views/apply-online/dock/personal/DockPersonalUserInfoQlf.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalProcess',
        name: 'dockPersonalProcess',
        component: () =>
          import('@/views/apply-online/dock/personal/DockPersonalProcess.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalProcessMain',
        name: 'dockPersonalProcessMain',
        component: () =>
          import(
            '@/views/apply-online/dock/personal/DockPersonalProcessMain.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockPersonalCompleted',
        name: 'dockPersonalCompleted',
        component: () =>
          import(
            '@/views/apply-online/dock/personal/DockPersonalCompleted.vue'
          ),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      //法人
      {
        path: '/dockCompanyApplyStep',
        name: 'dockCompanyApplyStep',
        component: () =>
          import('@/views/apply-online/dock/company/DockCompanyApplyStep.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockCompanyUserInfo',
        name: 'dockCompanyUserInfo',
        component: () =>
          import('@/views/apply-online/dock/company/DockCompanyUserInfo.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockCompanyProcess',
        name: 'dockCompanyProcess',
        component: () =>
          import('@/views/apply-online/dock/company/DockCompanyProcess.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
      {
        path: '/dockCompanyCompleted',
        name: 'dockCompanyCompleted',
        component: () =>
          import('@/views/apply-online/dock/company/DockCompanyCompleted.vue'),
        props: (route) => ({ ...route.query, ...route.params }),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});
// const dockPathArr = ['/dockPersonalApplyStep', '/dockCompanyApplyStep'];
// 钩子函数 路由拦截
// router.beforeEach((to, from, next) => {
//   const token = store.state.user.token;
//   if (dockPathArr.includes(to.path)) {
//     next();
//   } else if (!token && to.path !== '/login') {
//     next('/login');
//   } else {
//     next();
//   }
// });

router.afterEach((to) => {
  store.commit('router/setPath', to.path);
});

export default router;
